package com.lgy.springboot_example.controller;

import com.lgy.springboot_example.entity.OrderInfo;
import com.lgy.springboot_example.service.OrderInfoService;
import com.lgy.springboot_example.utils.DataResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单操作")
@RequestMapping("orderInfo")
@RestController
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;

    @ApiOperation("查询订单信息")
    @GetMapping("/selectAll")
    public DataResult<Object> selectAll() {
        return orderInfoService.getAll();
    }

    @ApiOperation("添加新订单")
    @PostMapping("/insertOrder")
    public DataResult<Object> insertOrder(@RequestBody OrderInfo orderInfo) {
        return orderInfoService.addOrderInfo(orderInfo);
    }

    @ApiOperation("修改订单信息")
    @PostMapping("/updateOrder")
    public DataResult<Object> updateOrder(@RequestBody OrderInfo orderInfo) {
        return orderInfoService.updateOrderInfo(orderInfo);
    }

    @ApiOperation("删除订单")
    @PostMapping("/delOrderById")
    @ApiImplicitParam(name = "id", value = "用户id", required = true)
    public DataResult<Object> delOrderById(@RequestParam("id") Integer id) {
        return orderInfoService.delOrderInfoById(id);
    }
}
